package com.ant.storage.controller;


import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.InvoiceInfoDto;
import com.ant.storage.dto.ReimburseInfoDto;
import com.ant.storage.dto.ReimburseInfosDto;
import com.ant.storage.handler.AntException;
import com.ant.storage.pojo.InvoiceInfo;
import com.ant.storage.pojo.Personnel;
import com.ant.storage.pojo.ReimburseInfoLog;
import com.ant.storage.pojo.UserInfo;
import com.ant.storage.service.IInvoiceInfoService;
import com.ant.storage.service.IPersonnelService;
import com.ant.storage.utils.UserInfoUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletContext;
import java.util.Calendar;
import java.util.Date;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author melon
 * @since 2023-11-24
 */
@RestController
@RequestMapping("/invoiceInfo")
public class InvoiceInfoController {

    @Autowired
    private IInvoiceInfoService invoiceInfoService;

    @ApiOperation(value = "获取报销信息列表接口")
    @GetMapping("/getInvoiceInfoPage")
    public ResultPage getInvoiceInfoPage(InvoiceInfoDto dto) {
        return ResultPage.success("获取成功", invoiceInfoService.getInvoiceInfoPage(dto));
    }

    @ApiOperation(value = "报销申请填写")
    @PostMapping("/InvoiceInfoSave")
    private ResultVo InvoiceInfoSave(@RequestBody InvoiceInfo dto) {
       // return null;
        return invoiceInfoService.InvoiceInfoSave(dto);
    }

    @ApiOperation(value = "通id获取详情")
    @GetMapping("/InvoiceInfoById/{id}")
    private ResultVo InvoiceInfoById(@PathVariable("id") Integer id) {
        return ResultVo.success("获取成功", invoiceInfoService.InvoiceInfoById(id));
    }

    @ApiOperation(value = "重复钉钉")
    @GetMapping("/rsendDingTalk/{id}")
    private ResultVo rsendDingTalk(@PathVariable("id") Integer id) throws Exception {
        return ResultVo.success("获取成功", invoiceInfoService.RsendDingTalk(id));
    }


    @ApiOperation(value = "重复钉钉s")
    @GetMapping("/rsendDingTalks/{id}/{uid}")
    private ResultVo rsendDingTalks(@PathVariable("id") Integer id, @PathVariable("uid") Integer uid) throws Exception {
        return ResultVo.success("获取成功", invoiceInfoService.RsendDingTalks(id, uid));
    }

    @ApiOperation(value = "删除")
    @GetMapping("/Update/{id}")
    private ResultVo Update(@PathVariable("id") Integer id) throws Exception {
        if (id == null) {
            throw new AntException("数据不存在");
        }
        return ResultVo.success("操作成功", invoiceInfoService.update(new UpdateWrapper<InvoiceInfo>()
                .set("Invoice_status", 4).eq("id", id)));
    }

    @ApiOperation(value = "获取上次钉钉申请")
    @GetMapping("/getHistoryDingTalk/{tid}")
    private ResultVo getHistoryDingTalk(@PathVariable("tid") Integer tid) throws Exception {
        return ResultVo.success("获取成功", invoiceInfoService.getHistoryDingTalk(tid));
    }


    @ApiOperation(value = "同步钉钉")
    @GetMapping("/syncDingTalks/{id}")
    private ResultVo syncDingTalks(@PathVariable("id") Integer id) {
        return invoiceInfoService.syncDingTalks(id);
    }


    public static void main(String[] args) {

        // 获取当前时间
        Date currentDate = new Date();
        // 设置开始时间
        Calendar startTime = Calendar.getInstance();
        startTime.set(Calendar.HOUR_OF_DAY, 8);
        startTime.set(Calendar.MINUTE, 0);
        startTime.set(Calendar.SECOND, 0);

        // 设置结束时间
        Calendar endTime = Calendar.getInstance();
        endTime.set(Calendar.HOUR_OF_DAY, 16);
        endTime.set(Calendar.MINUTE, 0);
        endTime.set(Calendar.SECOND, 0);

        // 判断当前时间是否在开始时间和结束时间之间
        if (currentDate.after(startTime.getTime()) && currentDate.before(endTime.getTime())) {
            System.out.println("当前时间在某一时间段内");
        } else {
            System.out.println("当前时间不在某一时间段内");
        }

    }


}
